//
//  PlayProgressView.m
//  LZMusicPlayer
//
//  Created by wulanzhou on 2016/10/20.
//  Copyright © 2016年 wulanzhou. All rights reserved.
//

#import "PlayProgressView.h"



@implementation PlayProgressView

+ (instancetype)playProgressViewOffsetY:(CGFloat)offsetY{

    PlayProgressView *progressView=[[PlayProgressView alloc] initWithFrame:CGRectMake(0, offsetY, [UIScreen mainScreen].bounds.size.width, 25)];
    
    return progressView;
}

- (instancetype)initWithFrame:(CGRect)frame{

    if (self=[super initWithFrame:frame]) {
        
        self.backgroundColor=[UIColor colorWithRed:50/255.0 green:208/255.0 blue:47/255.0 alpha:1.0];
        
        [self addSubview:self.startTimeLabel];
        [self addSubview:self.endTimeLabel];
        [self addSubview:self.sliderView];
        [self addSubview:self.sliderImageView];
    }
    
    return self;
}

- (void)setProgress:(float)progress{

    CGRect r=self.sliderImageView.frame;
    r.origin.x=self.sliderView.frame.size.width*progress+self.sliderView.frame.origin.x;
    self.sliderImageView.frame=r;
}

- (void)reset{
    self.startTimeLabel.text=@"0:00";
    self.endTimeLabel.text=@"0:00";
    [self setProgress:0.0];
}

#pragma mark -懒加载

- (UILabel *)startTimeLabel{

    if (!_startTimeLabel) {
        
        _startTimeLabel=[[UILabel alloc] initWithFrame:CGRectMake(2, 3, 40, 17)];
        _startTimeLabel.font=[UIFont systemFontOfSize:14.0f];
        _startTimeLabel.textColor=[UIColor whiteColor];
        _startTimeLabel.textAlignment=NSTextAlignmentRight;
        _startTimeLabel.text=@"0:00";
        
        
    }
    return _startTimeLabel;
}

- (UILabel *)endTimeLabel{

    if (!_endTimeLabel) {
        
        _endTimeLabel=[[UILabel alloc] initWithFrame:CGRectMake(self.bounds.size.width-42, 3, 40, 17)];
        _endTimeLabel.font=[UIFont systemFontOfSize:14.0f];
        _endTimeLabel.textColor=[UIColor whiteColor];
        //_endTimeLabel.textAlignment=NSTextAlignmentCenter;
        _endTimeLabel.text=@"0:00";
    }
    
    return _endTimeLabel;
}

- (UIView *)sliderView{

    if (!_sliderView) {
        
        _sliderView=[[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.startTimeLabel.frame)+5, (self.bounds.size.height-10)/2, self.endTimeLabel.frame.origin.x-CGRectGetMaxX(self.startTimeLabel.frame)-10, 10)];
        _sliderView.backgroundColor=[[UIColor grayColor] colorWithAlphaComponent:0.5];
        _sliderView.layer.cornerRadius=5.0;
        _sliderView.layer.masksToBounds=YES;
        
    }
    return _sliderView;
}

- (UIImageView *)sliderImageView{

    if (!_sliderImageView) {
        
        UIImage *image=[UIImage imageNamed:@"process_thumb"];
        _sliderImageView=[[UIImageView alloc] initWithFrame:CGRectMake(self.sliderView.frame.origin.x,(self.bounds.size.height-image.size.height)/2, image.size.width,image.size.height)];
        _sliderImageView.image=image;
    }
    return _sliderImageView;
}

@end
